package com.thoughtworks.bytecode2class.attribute;

import com.thoughtworks.bytecode2class.instruction.Instruction;
import com.thoughtworks.bytecode2class.instruction.InstructionFactory;

import java.util.LinkedList;
import java.util.List;

public class Code extends LinkedList<Instruction> {

    public static Code create(List<Byte> bytes) {
        Code code = new Code();
        for (int offset = 0; offset < bytes.size();) {
            Instruction instruction = InstructionFactory.create(bytes, offset);
            code.add(instruction);
            offset += (instruction.getParamCount() + 1);
        }
        return code;
    }

}
